using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using ShopForWeb.Dto.AjaxModels;
using ShopForWeb.Dto.ViewModels;
using ShopForWeb.Service;
using ShopForWeb.UI.Extensions;
using ShopForWeb.UI.Filters;

namespace ShopForWeb.UI.Controllers;

// [Authorize(Roles = "user")] //授权
[Route("orders")]
public class OrderController : Controller
{
  private OrderService _servcie;
  public OrderController(OrderService service)
  {
    _servcie = service;
  }

  [UserInfoFiler]
  [HttpGet("{page?}/{pageSize?}")]
  public IActionResult GetPage(int page = 1, int pageSize = 15)
  {
    return View();
  }
  [HttpPut("info")]
  public async Task<IActionResult> AddNewOrderAsync(List<OrderDetailViewModel> odvms)
  {
    int userID = this.GetUserID();
    int result = await _servcie.AddNewOrderAsync(userID, odvms);
    if (result == 0)
      return Json(new ResponseAjaxModel()
      {
        Status = 0,
        Message = "订单生成失败!"
      });
    else
      return Json(new ResponseAjaxModel()
      {
        Status = 1,
        Message = "订单生成完毕，请等待后续处理!"
      });
  }

}
